package mysql

import (
	"User/srv/UserAppConf"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var (
	DB  *gorm.DB
	err error
)

func Init() {
	AppConf := UserAppConf.AppConf.Mysql
	fmt.Println(AppConf)
	dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local", AppConf.User, AppConf.Password, AppConf.Host, AppConf.Port, AppConf.Database)
	DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		logx.Error("数据库链接失败")
	}
	logx.Info("数据库链接成功")
	DB.AutoMigrate(&User{})
}
